package com.cmy.test.mvp.ui

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.cmy.framework.room.test.manager.DBManger
import com.cmy.framework_base.basics.viewholder.BaseAdapter
import com.cmy.framework_utils.toast.toast
import com.cmy.test.mvp.databinding.ActivityMainBinding
import com.cmy.test.mvp.mvp.presenter.MainPresenter
import com.cmy.test.mvp.mvp.view.IMainView
import com.cmy.test.mvp.ui.list.*
import com.cmy.web.JumpPage
import com.cmy.web.WebType
import com.example.framework.mvp.mvp.view.BaseActivity

class MainActivity : BaseActivity<IMainView,MainPresenter>(){


    private val binding by lazy { ActivityMainBinding.inflate(layoutInflater) }

    private val adapter by lazy { BaseAdapter(
        mutableListOf(Test1ViewHolder.Test1Factory(),
                        Test2ViewHolder.Test2Factory()
    )) }
    override fun createPresenter(): MainPresenter = MainPresenter(this)

    override fun getContentView(): View = binding.root



    override fun initView(bundle: Bundle?) {
//        receiveEvent<String>("Text") { it,_ ->
//            val aa : Long = System.currentTimeMillis()
//            aa.dateTimeString()
////            TimeFormat.yyyy_MM_dd.format
//
//            "$it + aa".toast(this@MainActivity)
//        }

        binding.tvClick.setOnClickListener {
            JumpPage.startWebView(this, url = "https://www.baidu.com", type = WebType.Android)
//            DBManger.getInstance(this).insertTest("添加数据："+System.currentTimeMillis())

//         "存储的数据：${ DBManger.getInstance(this).findTestAll()?.size}".toast(this)
        }
    }

    override fun initData() {
//        binding .text.setOnClickListener {
//            sendEvent("Text","发送事件给当前页面")
//
//        }


        binding.recyclerView.layoutManager = LinearLayoutManager(this)
        binding.recyclerView.adapter = adapter


        adapter.setDataSource(mutableListOf(
            Test1ListData("测试1"),
            Test2ListData("测试1"),
            Test1ListData("测试1"),
            Test2ListData("测试1"),
            Test1ListData("测试1"),
            Test1ListData("测试1"),
            Test2ListData("测试1")))
    }

}
